package engine;

//RegisterSet
public class RegisterSet {
	RegisterItem register[];
	
	public RegisterSet(){
		register = new RegisterItem[8];
		for (int i = 0 ; i < 8; i++){
			register[i] = new RegisterItem();
			register[i].write(0);
		}
		
	}
	
	public void clearRegisters() {
		for(int i=0;i<8;i++) {
			register[i].station=-1;
			register[i].setIdle();
		}
	}
	
	public float read(String id){
		int rr=Integer.parseInt(id.substring(1));
		return register[rr].read();
	}
	
	public void write(String id, float data){
		int rr=Integer.parseInt(id.substring(1));
		register[rr].write(data);
	}
	
	public boolean isBusy(int id){
		return register[id].isBusy();
	}
	
	public void setBusy(String id){
		int rr=Integer.parseInt(id.substring(1));
		register[rr].setBusy();
	}
	
	public void setIdle(String id){
		int rr=Integer.parseInt(id.substring(1));
		register[rr].setIdle();
	}
	
	public void setStation(String rd, int station){
		int rr=Integer.parseInt(rd.substring(1));
		register[rr].setStation(station);
	}
	
	public int getStation(String id){
		int rr=Integer.parseInt(id.substring(1));
		return register[rr].getStation();
	}
}

class RegisterItem {
	int state;
	int station;
	float data;
	
	public RegisterItem(){
		state = 0;
		station = -1;
		data = 0f;
	}
	
	public boolean isBusy(){
		return (state == 1)? true : false;
	}
	
	public void setBusy(){
		state = 1;
	}
	
	public void setIdle(){
		state = 0;
	}
	
	public float read(){
		return data;
	}
	
	public void write(float data){
		this.data = data;
	}
	
	public void setStation(int s){
		station = s;
	}
	
	public int getStation(){
		return station;
	}
}